/*********************************************************************************
 * 
 * Author: wujunjie
 * Create Date: 2014-05-10
 * Description:
 *          
 * Revision History:
 *      Date          Author               Description
 * 
*********************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataFrameworkAccess;
using Xinkui.Entity.AutoGenerator;
using Xinkui.Common;
namespace Xinkui.DataAccess.AutoGenerator {
    public partial class MessageSendBoxDataAccess {
        public List<MessageSendBox_Entity> MessageSendBox_ListByPaging(int pageSize, int pageIndex, out int total) {
            total = 0;
            try {
                int tempRecord = 0;
                DataCommand cmd = DataCommandManager.GetDataCommand("MessageSendBox_ListByPaging");
                cmd.SetParameterValue("@PageSize", pageSize);
                cmd.SetParameterValue("@PageIndex", pageIndex);
                cmd.SetParameterValue("@RecordCount", tempRecord);
                List<MessageSendBox_Entity> pageList = cmd.ExecuteEntityList<MessageSendBox_Entity>();
                total = Convert.ToInt32(cmd.GetParameterValue("@RecordCount"));
                return pageList;
            }
            catch (Exception ex) {
                ExceptionHelper.ProcessException(ex);
            }

            return new List<MessageSendBox_Entity>(0);

        }

        public MessageSendBox_Entity MessageSendBox_View(System.Int32 MessageID) {
            MessageSendBox_Entity c = default(MessageSendBox_Entity);
            try {
                DataCommand cmd = DataCommandManager.GetDataCommand("MessageSendBox_View");
                cmd.SetParameterValue("@MessageID", MessageID);
                c = cmd.ExecuteEntity<MessageSendBox_Entity>();
            }
            catch (Exception ex) {
                ExceptionHelper.ProcessException(ex);
            }
            return c;
        }

        public MessageSendBox_Entity MessageSendBox_Add(MessageSendBox_Entity entity) {
            try {
                DataCommand cmd = DataCommandManager.GetDataCommand("MessageSendBox_Add");
                cmd.SetParameterValue("@MessageID", entity.MessageID);
                cmd.SetParameterValue("@MessageTitle", entity.MessageTitle);
                cmd.SetParameterValue("@UserID", entity.UserID);
                cmd.SetParameterValue("@MessageContent", entity.MessageContent);
                cmd.SetParameterValue("@Attach", entity.Attach);
                cmd.SetParameterValue("@SourceType", entity.SourceType);
                cmd.SetParameterValue("@SourceID", entity.SourceID);
                cmd.SetParameterValue("@SendDate", entity.SendDate);
                cmd.SetParameterValue("@MessageType", entity.MessageType);
                cmd.SetParameterValue("@IsDeleted", entity.IsDeleted);
                cmd.ExecuteNonQuery();

                entity.MessageID = (int)cmd.GetParameterValue("@MessageID");
            }
            catch (Exception ex) {
                ExceptionHelper.ProcessException(ex);
            }

            return entity;
        }

        public bool MessageSendBox_Update(MessageSendBox_Entity entity) {
            bool succ = false;
            try {
                DataCommand cmd = DataCommandManager.GetDataCommand("MessageSendBox_Update");
                cmd.SetParameterValue("@MessageID", entity.MessageID);
                cmd.SetParameterValue("@MessageTitle", entity.MessageTitle);
                cmd.SetParameterValue("@UserID", entity.UserID);
                cmd.SetParameterValue("@MessageContent", entity.MessageContent);
                cmd.SetParameterValue("@Attach", entity.Attach);
                cmd.SetParameterValue("@SourceType", entity.SourceType);
                cmd.SetParameterValue("@SourceID", entity.SourceID);
                cmd.SetParameterValue("@SendDate", entity.SendDate);
                cmd.SetParameterValue("@MessageType", entity.MessageType);
                cmd.SetParameterValue("@IsDeleted", entity.IsDeleted);
                cmd.ExecuteNonQuery();
                succ = true;
            }
            catch (Exception ex) {
                ExceptionHelper.ProcessException(ex);
            }
            return succ;
        }

        public bool MessageSendBox_Delete(System.Int32 MessageID) {
            bool succ = false;
            try {
                DataCommand cmd = DataCommandManager.GetDataCommand("MessageSendBox_Delete");
                cmd.SetParameterValue("@MessageID", MessageID);
                cmd.ExecuteNonQuery();
                succ = true;
            }
            catch (Exception ex) {
                ExceptionHelper.ProcessException(ex);
            }
            return succ;
        }

    }
}
